package com.wht.sip.core.transmit.model;


import com.wht.sip.utils.XmlUtil;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.dom4j.Element;

/**
 * 设备通道信息
 */
@Data
@Slf4j
public class DeviceChannel{

	/** 父设备编码 */
	private String parentDeviceId;

	/** 父设备名称 */
	private String parentName;

	/** 编码 */
	private String deviceId;

	/** 名称 */
	private String name;

	/** 设备厂商 */
	private String manufacturer;

	/** 设备型号 */
	private String model;

	/** 设备归属 */
	private String owner;

	/** 行政区域 */
	private String civilCode;

	/** 警区 */
	private String block;

	/** 安装地址 */
	private String address;

	/** 是否有子设备(必选)1有,0没有 */
	private Integer parental;

	/** 父节点ID */
	private String parentId;

	/** 信令安全模式 */
	private Integer safetyWay;

	/** 注册方式 */
	private Integer registerWay;

	/** 证书序列号 */
	private String certNum;

	/** 证书有效标识, 缺省为0;证书有效标识:0:无效 1:有效 */
	private Integer certifiable;

	/** 无效原因码(有证书且证书无效的设备必选) */
	private Integer errCode;

	/** 证书终止有效期(有证书且证书无效的设备必选) */
	private String endTime;

	/** 保密属性(必选)缺省为0;0-不涉密,1-涉密 */
	private Integer secrecy;

	/** 设备/系统IPv4/IPv6地址 */
	private String ipAddress;

	/** 设备/系统端口 */
	private Integer port;

	/** 设备口令 */
	private String password;

	/** 设备状态 */
	private String status;

	/** 经度 WGS-84坐标系 */
	private Double longitude;

	/** 纬度 WGS-84坐标系 */
	private Double latitude;

	/** 摄像机结构类型,标识摄像机类型: 1-球机; 2-半球; 3-固定枪机; 4-遥控枪机;5-遥控半球;6-多目设备的全景/拼接通道;7-多目设备的分割通道 */
	private Integer ptzType;

	/** 摄像机位置类型扩展。1-省际检查站、2-党政机关、3-车站码头、4-中心广场、5-体育场馆、6-商业中心、7-宗教场所、8-校园周边、9-治安复杂区域、10-交通干线 */
	private Integer positionType;

	/** 摄像机安装位置室外、室内属性。1-室外、2-室内。 */
	private Integer roomType;

	/** 用途属性， 1-治安、2-交通、3-重点。 */
	private Integer useType;

	/** 摄像机补光属性。1-无补光;2-红外补光;3-白光补光;4-激光补光;9-其他 */
	private Integer supplyLightType;

	/** 摄像机监视方位(光轴方向)属性。1-东(西向东)、2-西(东向西)、3-南(北向南)、4-北(南向北)、5-东南(西北到东南)、6-东北(西南到东北)、7-西南(东北到西南)、8-西北(东南到西北) */
	private Integer directionType;

	/** 摄像机支持的分辨率,可多值 */
	private String resolution;

	/** 虚拟组织所属的业务分组ID */
	private String businessGroupId;

	/** 下载倍速(可选),可多值 */
	private String downloadSpeed;

	/** 空域编码能力,取值0-不支持;1-1级增强(1个增强层);2-2级增强(2个增强层);3-3级增强(3个增强层) */
	private Integer svcSpaceSupportMod;

	/** 时域编码能力,取值0-不支持;1-1级增强;2-2级增强;3-3级增强(可选) */
	private Integer svcTimeSupportMode;

	/** 云台类型描述字符串 */
	private String ptzTypeText;

	/** 子设备数 */
	private int subCount;

	/** 是否含有音频 */
	private boolean hasAudio;

	/** GPS的更新时间 */
	private String gpsTime;

	/** 码流标识，优先级高于设备中码流标识，用于选择码流时组成码流标识。默认为null，不设置。可选值: stream/streamnumber/streamprofile/streamMode */
	private String streamIdentification;

	/** 通道类型， 默认0, 0： 普通通道，1 行政区划 2 业务分组/虚拟组织 */
	private int channelType;


	public void setPtzType(int ptzType) {
		this.ptzType = ptzType;
		switch (ptzType) {
			case 0:
				this.ptzTypeText = "未知";
				break;
			case 1:
				this.ptzTypeText = "球机";
				break;
			case 2:
				this.ptzTypeText = "半球";
				break;
			case 3:
				this.ptzTypeText = "固定枪机";
				break;
			case 4:
				this.ptzTypeText = "遥控枪机";
				break;
			case 5:
				this.ptzTypeText = "遥控半球";
				break;
			case 6:
				this.ptzTypeText = "多目设备的全景/拼接通道";
				break;
			case 7:
				this.ptzTypeText = "多目设备的分割通道";
				break;
		}
	}

	/**
	 * 解析DeviceChannel
	 * @param element
	 * @return
	 */
	public static DeviceChannel decode(Element element){

		DeviceChannel deviceChannel = new DeviceChannel();
		deviceChannel.setDeviceId(XmlUtil.getText(element, "DeviceID"));
		deviceChannel.setName(XmlUtil.getText(element, "Name"));
		deviceChannel.setManufacturer(XmlUtil.getText(element, "Manufacturer"));
		deviceChannel.setModel(XmlUtil.getText(element, "Model"));
		deviceChannel.setOwner(XmlUtil.getText(element, "Owner"));
		deviceChannel.setCivilCode(XmlUtil.getText(element, "CivilCode"));
		deviceChannel.setBlock(XmlUtil.getText(element, "Block"));
		deviceChannel.setAddress(XmlUtil.getText(element, "Address"));
		deviceChannel.setParental(XmlUtil.getInteger(element, "Parental"));
		deviceChannel.setParentId(XmlUtil.getText(element, "ParentID"));
		deviceChannel.setSafetyWay(XmlUtil.getInteger(element, "SafetyWay"));
		deviceChannel.setRegisterWay(XmlUtil.getInteger(element, "RegisterWay"));
		deviceChannel.setCertNum(XmlUtil.getText(element, "CertNum"));
		deviceChannel.setCertifiable(XmlUtil.getInteger(element, "Certifiable"));
		deviceChannel.setErrCode(XmlUtil.getInteger(element, "ErrCode"));
		deviceChannel.setEndTime(XmlUtil.getText(element, "EndTime"));
		deviceChannel.setSecrecy(XmlUtil.getInteger(element, "Secrecy"));
		deviceChannel.setIpAddress(XmlUtil.getText(element, "IPAddress"));
		deviceChannel.setPort(XmlUtil.getInteger(element, "Port"));
		deviceChannel.setPassword(XmlUtil.getText(element, "Password"));
		deviceChannel.setStatus(XmlUtil.getText(element, "Status"));
		deviceChannel.setLongitude(XmlUtil.getDouble(element, "Longitude"));
		deviceChannel.setLatitude(XmlUtil.getDouble(element, "Latitude"));

		Element info = element.element("Info");
//		deviceChannel.setPtzType(XmlUtil.getInteger(info, "PTZType"));
//		deviceChannel.setPositionType(XmlUtil.getInteger(info, "PositionType"));
//		deviceChannel.setRoomType(XmlUtil.getInteger(info, "RoomType"));
//		deviceChannel.setUseType(XmlUtil.getInteger(info, "UseType"));
//		deviceChannel.setSupplyLightType(XmlUtil.getInteger(info, "SupplyLightType"));
//		deviceChannel.setDirectionType(XmlUtil.getInteger(info, "DirectionType"));
//		deviceChannel.setResolution(XmlUtil.getText(info, "Resolution"));
//		deviceChannel.setBusinessGroupId(XmlUtil.getText(info, "BusinessGroupID"));
//		deviceChannel.setDownloadSpeed(XmlUtil.getText(info, "DownloadSpeed"));
//		deviceChannel.setSvcSpaceSupportMod(XmlUtil.getInteger(info, "SvcSpaceSupportMod"));
//		deviceChannel.setSvcTimeSupportMode(XmlUtil.getInteger(info, "SvcTimeSupportMode"));

		return deviceChannel;
	}

	public static DeviceChannel decodeWithOnlyDeviceId(Element element) {
		Element deviceElement = element.element("DeviceID");
		DeviceChannel deviceChannel = new DeviceChannel();
		deviceChannel.setDeviceId(deviceElement.getText());
		return deviceChannel;
	}



}
